import {reqGoodDetailInfo} from '@/api'

import { Message } from 'element-ui'
const actions ={
    //获取商品详情
    async getGoodDetailInfo({commit},skuId){
        const result =await reqGoodDetailInfo(skuId)
        if(result.code ===200){
            commit('SAVE_GOOD_DETAIL_INFO',result.data)
        }else{
            Message.error(result.message)
        }
    },
   
    
}
const mutations={
    SAVE_GOOD_DETAIL_INFO(state,info){
        state.goodDetailInfo = info
    },

}

const state = {
    goodDetailInfo:{
        categoryView:{},
        skuInfo:{
            skuImageList:[{}]
        },
        spuSaleAttrList:[{}],
        price:''
        }
}

const getters = {
    categoryView(state){
        return state.goodDetailInfo.categoryView
    },
    skuInfo(state){
        return state.goodDetailInfo.skuInfo
    },
    spuSaleAttrList(state){
        return state.goodDetailInfo.spuSaleAttrList
    },
    skuImageList(state){
        return state.goodDetailInfo.skuInfo.skuImageList
    }
}

export default {
    namespaced:true,
    actions,
    mutations,
    state,
    getters,
}